import {filterRenderType} from "@/components/Table/src/enum/filterRenderType";
import dayjs from "dayjs";

export default class resourceTableConfig {
    static select = {
        type: 'selection',
        fixed: 'left',
    }
    static resourceName = {
        title: '资源名称',
        key: 'resourceName',
        sorter: true,
        width: 200,
        filterType: filterRenderType.INPUT,
        render: (row, index) => {
            return h(
                'span',
                {
                    class: 'open-bookDetail',
                    onClick: () => {
                        console.log(row.resourceName);
                    },
                },
                {default: () => row.resourceName}
            );
        },
    }
    static property = {
        title: '类型',
        key: 'property',
        sorter: true,
        width: 100,
        filterMultiple: false,
        filterOptions: [
            {value: 0, label: '原创'}, {value: 1, label: '引进'}
        ],
        filterType: filterRenderType.SINGLESELECT,
        render: (row, index) => {
            return h(
                'span',
                {
                    class: '',
                },
                {default: () => row.property}
            );
        },
    }

    static isbnNum = {
        title: 'ISBN',
        key: 'isbnNum',
        width: 150,
        sorter: true,
        filterType: filterRenderType.INPUT,
    }

    static authorPenName = {
        title: '作者名',
        key: 'authorPenName',
        width: 250,
        sorter: true,
        filterType: filterRenderType.INPUT,
    }

    static pressName = {
        title: '出版社',
        key: 'pressName',
        width: 150,
        sorter: true,
        filterType: filterRenderType.INPUT,
    }

    static category = {
        title: '资源分类',
        key: 'category',
        width: 150,
        sorter: true,
        filterType: filterRenderType.INPUT,
    }

    static status = {
        title: '入库状态',
        key: 'status',
        sorter: true,
        width: 200,
        filterMultiple: false,
        filterOptions: [
            {value: 0, label: '未入库'}, {value: 1, label: '已入库'}
        ],
        filterType: filterRenderType.SINGLESELECT,
        render: (row, index) => {
            return h(
                'span',
                {
                    class: '',
                },
                // {default: () => (row.status === 1 ? '已入库' : '未入库')}
                {default: () => row.status}
            );
        },
    }
    static carrier = {
        title: '载体',
        key: 'carrier',
        sorter: true,
        width: 100,
        filterMultiple: false,
        filterOptions: [
            {value: 0, label: '未入库'}, {value: 1, label: '已入库'}
        ],
        filterType: filterRenderType.SINGLESELECT,
        render: (row, index) => {
            return h(
                'span',
                {
                    class: '',
                },
                {default: () => (row.resourceType === 1 ? '已入库' : '未入库')}
            );
        },
    }
    static insertTime = {
        title: '创建日期',
        key: 'insertTime',
        width: 150,
        sorter: true,
        filterType: filterRenderType.DATERANGEPICKER,
        render: (row, index) => {
            return h(
                'span',
                {
                    class: '',
                },
                {
                    default: () => (row.insertTime ? dayjs(row.insertTime).format('YYYY-MM-DD') : ''),
                }
            );
        },
    }

    static finalIssue = {
        title: '最新一期',
        key: 'finalIssue',
        width: 150,
        sorter: false,
    }

    static channel = {
        title: '频道',
        key: 'channel',
        sorter: true,
        width: 100,
        filterType: filterRenderType.SINGLESELECT,
        filterMultiple: false,
        filterOptions: [],
    }
    static bookState = {
        title: '全书状态',
        key: 'bookState',
        sorter: true,
        width: 100,
        filterType: filterRenderType.SINGLESELECT,
        filterMultiple: false,
        filterOptions: [],
    }
    static anchor = {
        title: '主播',
        key: 'anchor',
        width: 150,
        sorter: true,
        filterType: filterRenderType.INPUT,
    }
    static operationChannel = {
        title: '运营渠道',
        key: 'operationChannel',
        sorter: true,
        width: 200,
        filterType: filterRenderType.SINGLESELECT,
        filterMultiple: false,
        filterOptions: [],
    }
    static operation = (action) => {
        const {editRow, deleteRow,auditRow} = action
        return {
            title: '操作',
            key: 'operationTemplate',
            width: 100,
            fixed: 'right',
            render(row) {
                return h(
                    'span',
                    {
                        className: 'cursor-pointer flex items-center',
                        style: {
                            lineHeight: '15px',
                        },
                    },
                    [
                        h('i', {
                            className: 'icon iconfont icon-banquan_bianji',
                            style: {
                                margin: '0 10px 0 5px',
                            },
                            onClick: () => editRow(row),
                        }),
                        h('i', {
                            className: 'icon iconfont icon-banquan_shenhe',
                            style: {
                                margin: '0 10px 0 5px',
                            },
                            onClick: () => auditRow(row),
                        }),
                        h('i', {
                            className: 'icon iconfont icon-banquan_shanchu-03 red-icon',
                            onClick: () => deleteRow(row),
                        }),
                    ]
                );
            },
        }
    }

    /**
     * 图书资源列表配置
     */
    static getBookTableConfig(operationAction): Array<any> {
        return [
            this.select,
            this.resourceName,
            this.property,
            this.isbnNum,
            this.authorPenName,
            this.pressName,
            this.category,
            this.status,
            this.insertTime,
            this.operation(operationAction)
        ];
    }

    /**
     * 期刊资源列表配置
     */
    static getJournalTableConfig(operationAction): Array<any> {
        return [
            this.resourceName,
            this.finalIssue,
            this.property,
            this.isbnNum,
            this.pressName,
            this.category,
            this.status,
            this.insertTime,
            this.operation(operationAction)
        ];
    }

    /**
     * 音像制品列表配置
     */
    static getAudiovisualTableConfig(): Array<any> {
        return [
            this.resourceName,
            this.property,
            this.authorPenName,
            this.isbnNum,
            this.category,
            this.status,
            this.insertTime,
            this.operation
        ];
    }

    /**
     * 电子出版物列表配置
     */
    static getEpubTableConfig(): Array<any> {
        return [
            this.resourceName,
            this.property,
            this.authorPenName,
            this.isbnNum,
            this.category,
            this.carrier,
            this.status,
            this.insertTime,
            this.operation
        ];
    }

    /**
     * 网络文学列表配置
     */
    static getNetliteratureTableConfig(): Array<any> {
        return [
            this.resourceName,
            this.property,
            this.authorPenName,
            this.channel,
            this.category,
            this.bookState,
            this.status,
            this.insertTime,
            this.operation
        ];
    }


    // 资源管理表格
    static getResTable(): Array<any> {
        return [
            this.resourceName,
            this.property,
            this.category,
            this.status,
            this.insertTime,
            this.operation
        ];
    }
}
